package com.sq.partner.manager.controller;

import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.sq.partner.manager.dao.INlifePlanDao;
import com.sq.partner.manager.service.*;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sq.partner.manager.common.Constants;
import com.sq.partner.manager.common.DictCache;
import com.sq.partner.manager.common.Result;
import com.sq.partner.manager.dao.INlifeProdDao;
import com.sq.partner.manager.mybatis.model.CoreDept;
import com.sq.partner.manager.mybatis.model.DictDto;
import com.sq.partner.manager.mybatis.model.GatewayChannelInfo;
import com.sq.partner.manager.mybatis.model.GatewayUser;
import com.sq.partner.manager.mybatis.model.NlifePlan;
import com.sq.partner.manager.mybatis.model.NlifeProd;
import com.sq.partner.manager.mybatis.model.TradPlanSale;
import com.sq.partner.manager.util.LogUtil;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.SqlUtil;
import com.sq.partner.manager.util.StrUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

/**
 * @date 2017-05-18 新意健险方案审核
 * @author     JIJINBO
 */
@Controller
@RequestMapping("/nlifePlanCheck")
public class NlifePlanCheckController {
	private static Logger logger = LogUtil.getLog(NlifePlanCheckController.class);
	
	@Resource
	private INlifePlanCheckService nlifePlanCheckService;
	
	@Resource
	private INlifeProdDao nlifeProdDao;

	@Resource
	private INlifePlanDao nlifePlanDao;

	@Resource
	INlifePlanConfigService nlifePlanConfigService;

	@Resource
	TradPlanSaleService tradPlanSaleService;
	
	@Resource
	private TradSmsTemplateService tradSmsTemplateService;
	
	@Resource
	private IGatewayClearCacheManager gatewayClearCacheManager;

	@Resource
	private IGatewayChannelInfoConfigService iGatewayChannelInfoConfigService;
	/**
	 * 跳转方案审核列表页面
	 */
	@RequestMapping(value = "/list")
	public String list() throws Exception {
		return "nlifeProduct/planCheck/list";
	}
	/**
	 * 分页条件查询合作伙伴
	 * @param session
	 * @param page
	 * @param channelInfo
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryChannelInfoPageByCriteria")
	@ResponseBody
	public Page<GatewayChannelInfo> queryChannelInfoPageByCriteria(HttpSession session,Page<GatewayChannelInfo> page,GatewayChannelInfo channelInfo) throws Exception{
		GatewayUser gatewayuser=(GatewayUser) session.getAttribute(Constants.SESSION_USER);
		page.setDepts(gatewayuser.getDepts());
		page.setType(channelInfo);
		
		page = nlifePlanCheckService.queryChannelInfoPageByCriteria(page);
		
		return page;
	}
	/**
	 * 分页条件查询方案
	 * @param session
	 * @param page
	 * @param nlifePlan
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryUnApproveNlifePlanPageByCriteria")
	@ResponseBody
	public Page<Map<String,Object>> queryUnApproveNlifePlanPageByCriteria(HttpSession session,Page<Map<String,Object>> page,NlifePlan nlifePlan) throws Exception{
		
		GatewayUser user=(GatewayUser) session.getAttribute(Constants.SESSION_USER);
		String privilegedDeptStr = user.getDepartmentStr();
		
		Map<String,Object> paramMap = SqlUtil.buildPageMap(page);
		paramMap.put("privilegedDeptStr", privilegedDeptStr==null?"''":privilegedDeptStr.substring(1, 3));
		paramMap.put("partnerNo", nlifePlan.getPartnerNo()==null?"":nlifePlan.getPartnerNo());
		paramMap.put("planNo", nlifePlan.getPlanNo()==null?"":nlifePlan.getPlanNo());
		paramMap.put("planName", nlifePlan.getPlanName()==null?"":nlifePlan.getPlanName());
		paramMap.put("prodCode", nlifePlan.getProdCode()==null?"":nlifePlan.getProdCode());
		
		page.setMap(paramMap);
		page = nlifePlanCheckService.queryUnApproveNlifePlanPageByCriteria(page);
		return page;
	}
//	/**
//	 * 删除方案
//	 * @param nlifePlan
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value = "/delNlifePlanCheck")
//	@ResponseBody
//	public Result delNlifePlan(NlifePlan nlifePlan) throws Exception{
//		Result result = nlifePlanCheckService.delNlifePlan(nlifePlan);
//		return result;
//	}
	/**
	 * 跳转至编辑方案审核页面
	 * @param model
	 * @param planNo
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/toCheckNlifePlan")
	public String toEditNlifePlan(ModelMap model, String planNo) throws Exception {
		//争议处理方式
		List<DictDto> dicputeTypes=DictCache.getDict(Constants.DICT_DICPUTE_TYPE);
		//初始化方案销售类型
		List<DictDto> agentTypes = DictCache.getDict(Constants.DICT_AGENT_TYPE);
		//仲裁委员会名称
		List<DictDto> arbitrationDepts=DictCache.getDict(Constants.DICT_ARBITRATION_DEPT);
		//联合出单方案
		List<DictDto> unionTypes = DictCache.getDict(Constants.DICT_UNION_TYPE);
		//电子保单文件方式
		List<DictDto> fileTypes = DictCache.getDict(Constants.DICT_FILE_TYPE);
		
		model.put("dicputeTypes", dicputeTypes);
		model.put("arbitrationDepts", arbitrationDepts);
		model.put("agentTypes", agentTypes);
		model.put("unionTypes", unionTypes);
		model.put("fileTypes", fileTypes);
		nlifePlanCheckService.toCheckNlifePlan(model,planNo);
		
		return "nlifeProduct/planCheck/addOrCheck";
	}
	
	/**
	 * 方案审核完后返回方案审核列表页面
	 * @param flag
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value = "/successBack")
	public String successBack(HttpServletRequest request, String flag) throws Exception {
		request.setAttribute("flag", flag);
		
		return "nlifeProduct/planCheck/list";
	}
	
	/**
	 * 编辑方案时，加载方案审核信息数据
	 * @param planNo
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/loadNlifePlanCheck")
	@ResponseBody
	public Map<String,Object> loadNlifePlan(String planNo) throws Exception{
		Map<String, Object> map = nlifePlanCheckService.loadNlifePlan(planNo);
		/**销售人员信息*/
		Map<String, String> salemap=new HashMap<String, String>();
		salemap.put("planCode", planNo);
		String cancelTemplate =((NlifePlan)map.get("nlifePlan")).getCancelTemplate();
		if(!"".equals(cancelTemplate) && null != cancelTemplate){
			String cancelTemplate_val = tradSmsTemplateService.queryTradeByCode(cancelTemplate).getSmsTemplateText();
			map.put("cancelTemplate_val", cancelTemplate_val);
		}
		String messageTemplate =((NlifePlan)map.get("nlifePlan")).getMessageTemplate();
		if(!"".equals(messageTemplate) && null != messageTemplate){
			String messageTemplate_val = tradSmsTemplateService.queryTradeByCode(messageTemplate).getSmsTemplateText();
			map.put("messageTemplate_val", messageTemplate_val);
		}
		List<TradPlanSale> sales=tradPlanSaleService.queryTrade(salemap);
		if(sales!=null&&sales.size()>0){
			map.put("sales", sales);
		}
		if(sales!=null&&sales.size()>0){
			/**销售人员字典*/
			List<DictDto> dictDtos=DictCache.getDict("role_stype");
			map.put("sales", sales);
			for (TradPlanSale tradPlanSale : sales) {
				for (DictDto dictDto : dictDtos) {
					if(dictDto.getCode().equals(tradPlanSale.getPersonType())){
						tradPlanSale.setSaleTypeName(dictDto.getCodeName());
					}
				}
			}
		}
		return map;
	}
	
	/**
	 * 分页条件查询新意健险产品
	 * @param page
	 * @param nlifeProd
	 * @param startDateBegin
	 * @param startDateEnd
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryNlifeProdPageByCriteria")
	@ResponseBody
	public Page<NlifeProd> queryNlifeProdPageByCriteria(Page<NlifeProd> page, NlifeProd nlifeProd, String startDateBegin, String startDateEnd) throws Exception{

		Map<String,Object> paramMap = SqlUtil.buildPageMap(page);
		paramMap.put("prodCode", nlifeProd.getProdCode()==null?"":nlifeProd.getProdCode());
		paramMap.put("prodName", nlifeProd.getProdName()==null?"":nlifeProd.getProdName());
		paramMap.put("startDateBegin", startDateBegin==null?"":startDateBegin);
		paramMap.put("startDateEnd", startDateEnd==null?"":startDateEnd);
		paramMap.put("status", "1");//1为有效产品
		
		page.setMap(paramMap);
		
		page = nlifePlanCheckService.queryNlifeProdPageByCriteria(page);
		return page;
	}
	/**
	 * 修改方案审核页面,根据产品编号加载方案的所有信息
	 * @param nlifePlan
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/addOrCheckNlifePlanCheck")
	@ResponseBody 
	public Result addOrUpdateNlifePlan(NlifePlan nlifePlan,String oldPlanNo,String oldPartnerNo,String oldAgentType) throws Exception{
		String planName = nlifePlan.getPlanName();
		if(StrUtil.isEmpty(planName)) return Result.error("投保方案名称不能为空");
		
		String prodCode = nlifePlan.getProdCode();
		if(StrUtil.isEmpty(prodCode)) return Result.error("产品编号不能为空");
		
		String partnerNo = nlifePlan.getPartnerNo();
		if(StrUtil.isEmpty(partnerNo)) return Result.error("合作伙伴代码不能为空");
		
		//1、合作伙伴代理3、个人代理4、总对总代理
		NlifeProd nlifeProd = nlifeProdDao.queryProdInfoById(nlifePlan.getProdCode());
		String agentType = nlifePlan.getAgentType();
		String dptCde = nlifePlan.getDptCde();
		if("1".equals(agentType)){
			if(StrUtil.isEmpty(dptCde)) return Result.error("出单机构不能为空");
			
			String channleCode = nlifePlan.getChannleCode();
			if(StrUtil.isEmpty(channleCode)) return Result.error("归属渠道不能为空");
			
			String channleType = nlifePlan.getChannleType();
			if(StrUtil.isEmpty(channleType)) return Result.error("渠道类型不能为空");
			
			String newBsnsType = nlifePlan.getNewBsnsType();
			if(StrUtil.isEmpty(newBsnsType)) return Result.error("业务来源不能为空");
		}
		
		BigDecimal commRate = nlifePlan.getCommRate();
		//1、合作伙伴代理3、个人代理4、总对总代理
		String empNo = nlifePlan.getEmpNo();
		String empName = nlifePlan.getEmpName();
		String teamCode = nlifePlan.getTeamCode();
		String teamName = nlifePlan.getTeamName();
		String categoryCode = nlifePlan.getCategoryCode();
		String agentNo = nlifePlan.getAgentNo();
		String protocolNo = nlifePlan.getProtocolNo();
		String serviceCode = nlifePlan.getServiceCode();
		String serviceName = nlifePlan.getServiceName();
		String isSendEmail = nlifePlan.getIsSendEmail();
		String emailTemplate = nlifePlan.getEmailTemplate();
		if("1".equals(isSendEmail)&&emailTemplate==null){
			return Result.error("请输入邮件模板");
		}
		emailTemplate = URLDecoder.decode(emailTemplate, "UTF-8");
		nlifePlan.setEmailTemplate(emailTemplate);
		if("1".equals(agentType)){
			if(StrUtil.isEmpty(empNo)) return Result.error("业务员代码不能为空");
		/*	if(StrUtil.isEmpty(empName)) return Result.error("业务员名称不能为空");*/
			if(StrUtil.isEmpty(teamCode)) return Result.error("团队代码不能为空");
			if(StrUtil.isEmpty(teamName)) return Result.error("团队名称不能为空");
			
			//原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填
			if("19002".equals(categoryCode) || "19003".equals(categoryCode)){
				if(StrUtil.isEmpty(agentNo)) return Result.error("代理人代码不能为空");
				if(StrUtil.isEmpty(protocolNo))	return Result.error("代理协议号不能为空");
			}	
			if(StrUtil.isEmpty(serviceCode)) return Result.error("服务代码不能为空");
		}
		String isEpolicy = nlifePlan.getIsEpolicy();
		if(StrUtil.isEmpty(isEpolicy)) return Result.error("请选择是否电子保单");
		
		//是否打印单证
		String isPrintCard = nlifePlan.getIsPrintCard();
		String cardType = nlifePlan.getCardType();
		String cardApplicant = nlifePlan.getCardApplicant();	
		//当“是否发送短信”的值为“是”时，短信模板配置
		String isMessage = nlifePlan.getIsMessage();
		String messageReceiver = nlifePlan.getMessageReceiver();
		String messageTemplate = nlifePlan.getMessageTemplate();
		messageTemplate = URLDecoder.decode(messageTemplate, "UTF-8");
		nlifePlan.setMessageTemplate(messageTemplate);
		String selectAccessorylistStr = nlifePlan.getSelAccessory();
		String ids="";
		if(!StrUtil.isEmpty(selectAccessorylistStr)){
			//创建一个JsonPaser
			JsonParser jsonParser=new JsonParser();
			//通过JsonPaser对象可以把字符串解析成一个JsonElement对象
			JsonElement element=jsonParser.parse(selectAccessorylistStr);
			//把JsonElement转化成jsonArray
			JsonArray jsonArray=null;
			//判断element是不是jsonArray
			if(element.isJsonArray()){
				jsonArray=element.getAsJsonArray();
			}
			//循环得到id的拼接字符串
			for (JsonElement jsonElement : jsonArray) {
				String id=jsonElement.getAsJsonObject().get("id").getAsString();
				ids=ids+id+",";
			}
			//如果长度不为0.去除，
			if(ids.length()>0){
				ids=ids.substring(0, ids.length()-1);
			}					
		}
		nlifePlan.setSelAccessory(ids);
		
		String planNo = nlifePlan.getPlanNo();
		Result result = null;
		if(StrUtil.isNotEmpty(planNo)){
			result = nlifePlanCheckService.checkNlifePlan(nlifePlan,nlifeProd);
			//清除缓存
			//gatewayClearCacheManager.clearNlifeCacheInfoManager();
		}
		return result;
	}

	/**
	 * 批量删除
	 * @param planList
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/batchDeleteNlifePlan")
	@ResponseBody
	public Result batchDeleteNlifePlan(@RequestBody List<NlifePlan> planList, HttpSession session) throws Exception {
		String successMsg = "";
		for (NlifePlan nlifePlan : planList) {
			Result result = nlifePlanConfigService.delNlifePlan(nlifePlan, session);
			String res = result.getResult();
			String msg = result.getMessage();
			if (res.equals("error")) {
				return Result.error(nlifePlan.getPlanNo() + msg);
			} else {
				successMsg = msg;
			}
		}
		return Result.success(successMsg);
	}

	/**
	 * 批量审核
	 * @param planList
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/batchCheckPlan")
	@ResponseBody
	public Result batchCheckPlan(@RequestParam List<String> planList,@RequestParam String checkOpinion,@RequestParam String flag) throws Exception {
		logger.info(planList);
		StringBuilder message = new StringBuilder();
		for (int i = 0; i < planList.size(); i++) {
			String planNo = planList.get(i);
			NlifePlan nlifePlan = nlifePlanDao.queryById(planNo);
			if (!StrUtil.isEmpty(nlifePlan.getState()) && nlifePlan.getState().equals("1")) {
				return Result.error(planNo + "投保方案状态为已审核状态");
			}
			String planName = nlifePlan.getPlanName();
			if(StrUtil.isEmpty(planName)) return Result.error(planNo + "投保方案名称不能为空");

			String prodCode = nlifePlan.getProdCode();
			if(StrUtil.isEmpty(prodCode)) return Result.error(planNo + "产品编号不能为空");

			String partnerNo = nlifePlan.getPartnerNo();
			if(StrUtil.isEmpty(partnerNo)) return Result.error(planNo + "合作伙伴代码不能为空");

			//1、合作伙伴代理3、个人代理4、总对总代理
			NlifeProd nlifeProd = nlifeProdDao.queryProdInfoById(nlifePlan.getProdCode());
			String agentType = nlifePlan.getAgentType();
			String dptCde = nlifePlan.getDptCde();
			if("1".equals(agentType)){
				if(StrUtil.isEmpty(dptCde)) return Result.error(planNo + "出单机构不能为空");

				String channleCode = nlifePlan.getChannleCode();
				if(StrUtil.isEmpty(channleCode)) return Result.error(planNo + "归属渠道不能为空");

				String channleType = nlifePlan.getChannleType();
				if(StrUtil.isEmpty(channleType)) return Result.error(planNo + "渠道类型不能为空");

				String newBsnsType = nlifePlan.getNewBsnsType();
				if(StrUtil.isEmpty(newBsnsType)) return Result.error(planNo + "业务来源不能为空");
				if (StrUtil.isEmpty(nlifePlan.getEmpNo())) return Result.error(planNo + "业务员代码不能为空");
				String partnerType = iGatewayChannelInfoConfigService.queryIfInternetPlan(nlifePlan.getPartnerNo());
				if("1".equals(partnerType) && !"Y".equalsIgnoreCase(nlifePlan.getIsPushedSalesInfo())){
					return Result.error(planNo + "该方案暂未推送销售信息，不能审核通过");
				}
			}
			//1、合作伙伴代理3、个人代理4、总对总代理
			String empNo = nlifePlan.getEmpNo();
			String teamCode = nlifePlan.getTeamCode();
			String teamName = nlifePlan.getTeamName();
			String categoryCode = nlifePlan.getCategoryCode();
			String agentNo = nlifePlan.getAgentNo();
			String protocolNo = nlifePlan.getProtocolNo();
			String serviceCode = nlifePlan.getServiceCode();
			String isSendEmail = nlifePlan.getIsSendEmail();
			String emailTemplate = nlifePlan.getEmailTemplate();
			if("1".equals(isSendEmail)&&emailTemplate==null){
				return Result.error("请输入邮件模板");
			}
			nlifePlan.setEmailTemplate(emailTemplate);
			if("1".equals(agentType)){
				if(StrUtil.isEmpty(empNo)) return Result.error(planNo + "业务员代码不能为空");
				/*	if(StrUtil.isEmpty(empName)) return Result.error("业务员名称不能为空");*/
				if(StrUtil.isEmpty(teamCode)) return Result.error(planNo + "团队代码不能为空");
				if(StrUtil.isEmpty(teamName)) return Result.error(planNo + "团队名称不能为空");

				//原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填
				if("19002".equals(categoryCode) || "19003".equals(categoryCode)){
					if(StrUtil.isEmpty(agentNo)) return Result.error(planNo + "代理人代码不能为空");
					if(StrUtil.isEmpty(protocolNo))	return Result.error(planNo + "代理协议号不能为空");
				}
				if(StrUtil.isEmpty(serviceCode)) return Result.error(planNo + "服务代码不能为空");
			}
			String isEpolicy = nlifePlan.getIsEpolicy();
			if(StrUtil.isEmpty(isEpolicy)) return Result.error(planNo + "请选择是否电子保单");
			if (flag != null && flag.equals("batchCheck")){
				nlifePlan.setState("1");
				nlifePlan.setCheckStatus("已审核");
			} else if (flag != null && flag.equals("batchBack")) {
				nlifePlan.setState("0");
				nlifePlan.setCheckStatus("退回");
			}
			nlifePlan.setCheckOpinion(checkOpinion);
			Result result;
			if(StrUtil.isNotEmpty(planNo)){
				result = nlifePlanCheckService.checkNlifePlan(nlifePlan,nlifeProd);
				if (result.getResult().equals("error")) {
					return result;
				}
				message.append(planNo).append("方案").append(result.getMessage());
				//清除缓存
				//gatewayClearCacheManager.clearNlifeCacheInfoManager();
			}
		}
		return Result.success(message);
	}
	/**
	 * 加载方案关联个人代理、总对总代理信息
	 * @param page
	 * @param planNo
	 * @param agentType
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryAgentInfoRelaPageByCriteria")
	@ResponseBody
	public Page<Map<String,Object>> queryAgentInfoRelaPageByCriteria(Page<Map<String,Object>> page,
							  		String planNo,String agentType) throws Exception{
		if(StrUtil.isEmpty(planNo)){
			page.setResult("planNo不能为空");
			return page;
		}
		if(!("3".equals(agentType) || "4".equals(agentType))){
			page.setResult("agentType取值有误");
			return page;
		}
		
		Map<String,Object> paramMap = SqlUtil.buildPageMap(page);
		paramMap.put("planNo", planNo);
		
		page.setMap(paramMap);
		
		page = nlifePlanCheckService.queryAgentInfoRelaPageByCriteria(page,agentType);
		
		return page;
	}
	
	/**
	 * 加载个人代理、总对总代理信息
	 * @param page
	 * @param planNo
	 * @param agentType
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryAgentInfoPageByCriteria")
	@ResponseBody
	public Page<Map<String,Object>> queryAgentInfoPageByCriteria(Page<Map<String,Object>> page, String planNo, String partnerNo, String agentType,
												String confStatus, String userCode, String userName, String branch, String branchName) throws Exception{
		if(StrUtil.isEmpty(planNo)){
			page.setResult("planNo不能为空");
			return page;
		}
		if(StrUtil.isEmpty(partnerNo)){
			page.setResult("partnerNo不能为空");
			return page;
		}
		if(!("3".equals(agentType) || "4".equals(agentType))){
			page.setResult("agentType取值有误");
			return page;
		}
		
		Map<String,Object> paramMap = SqlUtil.buildPageMap(page);
		paramMap.put("planNo", planNo);
		paramMap.put("partnerNo", partnerNo);
		paramMap.put("agentType", agentType);
		paramMap.put("confStatus", confStatus);
		paramMap.put("userCode", userCode);
		paramMap.put("userName", userName);
		paramMap.put("branch", branch);
		paramMap.put("branchName", branchName);
		
		page.setMap(paramMap);
		
		page = nlifePlanCheckService.queryAgentInfoPageByCriteria(page,agentType);
		
		return page;
	}
	
	/**
	 * 更新方案关联的个人代理信息
	 * @param session
	 * @param planNo
	 * @param isPrintCard
	 * @param agentInfoListStr
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateAgentInfoRela")
	@ResponseBody
	public Result updateAgentInfoRela(HttpSession session,String planNo, String isPrintCard, String agentInfoListStr) throws Exception{
		GatewayUser user=(GatewayUser) session.getAttribute(Constants.SESSION_USER);

		if(StrUtil.isEmpty(planNo)){ return Result.error("方案号不能为空"); }
		if(StrUtil.isEmpty(agentInfoListStr)){ return Result.error("代理信息不能为空"); }
		
		if("Y".equals(isPrintCard)){
			//创建一个JsonParser
			JsonParser jsonParser = new JsonParser();
			//通过JsonParser对象可以把json格式的字符串解析成一个JsonElement对象
			JsonElement jsonElement = jsonParser.parse(agentInfoListStr);
			//把JsonElement对象转换成JsonArray
			JsonArray jsonArray = null;
			if(jsonElement.isJsonArray()){
				jsonArray = jsonElement.getAsJsonArray();
			}else{
				return Result.error("无效的代理信息");
			}
			for (JsonElement je : jsonArray) {
				String id =je.getAsJsonObject().get("id").getAsString();
				String cardapplicant=je.getAsJsonObject().get("cardapplicant").getAsString();
				if(StrUtil.isEmpty(id)||StrUtil.isEmpty(cardapplicant)){
					return Result.error("您配置的代理信息中存在单证领用人为空的,单证领用人不能为空");
				}
			}
		}
		
		Result result = nlifePlanCheckService.updateAgentInfoRela(user.getUserid(), planNo, agentInfoListStr);
		
		return result;
	}
}
